package com.x.crm.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.crm.dao.CustomerShopDao;
import com.x.crm.manage.CustomerManage;
import com.x.crm.manage.CustomerShopManage;
import com.x.crm.manage.IntentionManage;
import com.x.crm.model.Customer;
import com.x.crm.model.CustomerShop;
import com.x.crm.model.Intention;
import com.x.crm.rpc.CustomerShopRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sound.midi.Soundbank;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/2.
 */
@Component
@Service(interfaceName = "com.x.crm.rpc.CustomerShopRpcService", timeout = 60000)
public class CustomerShopService extends BaseService implements CustomerShopRpcService {

	@Autowired
	private CustomerShopDao customerShopDao;

	@Autowired
	private CustomerShopManage customerShopManage;


	public List<CustomerShop> selectCustomerShopList(CustomerShop customerShop) {
		try {
			return customerShopDao.selectCustomerShopList(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}


	public int selectCustomerShopNum(CustomerShop customerShop) {
		try {
			return customerShopDao.selectCustomerShopNum(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	// CRM 已更进，已预约日统计
	public List<Map<String, Object>>  selectFollowUpCustomerShopList(CustomerShop customerShop, String searchMode) {
		try {
			return customerShopDao.selectFollowUpCustomerShopList(customerShop,searchMode);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	// CRM 已成交日统计
	public List<Map<String, Object>>  selectFixtureCustomerShopList(CustomerShop customerShop, Intention intention, String searchMode) {
		try {
			return customerShopDao.selectFixtureCustomerShopList(customerShop,intention,searchMode);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}
	// CRM 跟进 预约 日统计明细
	public List<CustomerShop> selectFollowUpCustomerShopInfoList(CustomerShop customerShop) {
		try {
			return customerShopDao.selectFollowUpCustomerShopInfoList(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	// CRM 已成交日统计明细
	public List<CustomerShop> selectFixtureCustomerShopInfoList(CustomerShop customerShop,Intention intention) {
		try {
			return customerShopDao.selectFixtureCustomerShopInfoList(customerShop,intention);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	public CustomerShop insertCustomerShop(CustomerShop customerShop) {
		try {
			return this.insert(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	public int updateCustomerShop(CustomerShop customerShop) {
		try {
			return this.update(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}


	public int updateCustomerShopAlloctInfo(CustomerShop customerShop) {
		try {
			return customerShopManage.updateCustomerShopAlloctInfo(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}


	public int updateCustomerShopReleaseInfo(CustomerShop customerShop) {
		try {
			return customerShopManage.updateCustomerShopReleaseInfo(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}



	public List<CustomerShop> selectSimpleCustomerShopList(CustomerShop customerShop) {
		try {
			return customerShopDao.selectSimpleCustomerShopList(customerShop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}


	public Map<String,Object> selectFollowUpNum(CustomerShop customerShop, Date queryDate) {
		try {
			return customerShopDao.selectFollowUpNum(customerShop, queryDate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	public Map<String,Object> selectOrderUpNum(CustomerShop customerShop, Date queryDate) {
		try {
			return customerShopDao.selectOrderUpNum(customerShop,queryDate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	public Map<String,Object> selectFixtureNum(CustomerShop customerShop , Date queryDate) {
		try {
			return customerShopDao.selectFixtureNum(customerShop, queryDate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}


}
